<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.keyword" placeholder="关键字" size="small"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getTableData" icon="el-icon-search" size="small">执行查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary"  icon="el-icon-plus" size="small"  v-on:click="addTeacher" >讲师新增</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="tableData" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column  label="头像">
				<template scope="scope">
					<el-image style="width: 40px;height: 40px"
							:src="scope.row.headImg"></el-image>
				</template>
			</el-table-column>
			<el-table-column prop="name" label="名称" >
			</el-table-column>
			<el-table-column prop="position" label="职位"  >
			</el-table-column>
			<el-table-column prop="tags" label="标签"  >
			</el-table-column>
			<el-table-column prop="intro" label="介绍" width="200" >
				<template slot-scope="scope">
					<el-popover trigger="hover" placement="top" >
						<div style="width: 400px;">{{ scope.row.intro }}</div>
						<div slot="reference" class="name-wrapper" >
							<el-tag >
								{{ scope.row.intro }}
							</el-tag>
						</div>
					</el-popover>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="200">
				<template scope="scope">
					<el-button size="small"  @click="edit(scope.row)" icon="el-icon-edit" type="primary">编辑</el-button>
					<el-button type="danger" size="small" @click="del(scope.row)" icon="el-icon-remove">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0" icon="el-icon-remove" size="small">批量删除</el-button>
      <el-pagination
          layout="total,sizes,prev, pager, next"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[5,10,15,20]"
          :page-size="pageSize"
          :total="total"
          :current-page="pageNo"
          style="float:right;">
      </el-pagination>
		</el-col>
    <!--新增界面-->
    <el-dialog title="新增" :visible.sync="addFormVisible"  :close-on-click-modal="false">
      <el-form :model="addForm" label-width="80px"  ref="addForm">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="addForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="简介" prop="intro">
          <el-input v-model="addForm.intro" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item label="技术栈" prop="technology">
          <el-input v-model="addForm.technology" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="定位" prop="position">
          <el-input v-model="addForm.position" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="标签" prop="tags">
          <el-input v-model="addForm.tags" auto-complete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="addSubmit" >提交</el-button>
      </div>
    </el-dialog>

	</section>
</template>

<script>

	export default {
		data() {
			return {
				filters: {
					keyword: ''
				},
				tableData: [],
        pageNo:1,//当前页,要传递到后台的
        total:0, //分页总数
        pageSize:5,
				listLoading: false,
				sels:[],
        //---------------------新增业务相关数据
        addFormVisible:false,
        addForm:{
          id:null,
          name:"",
          intro:"",
          technology:"",
          position:"",
          headImg:"",
          tags:"",
        }
			}

		},
		methods: {
			selsChange(sels){
				this.sels = sels;
			},
			//性别显示转换
			formatState: function (row, column) {
				return row.sex == 1 ? '禁用' : '启用';
			},
      handleSizeChange(val){
        this.pageSize = val;
        this.getTableData();
      },
      handleCurrentChange(page){
        this.pageNo = page;
        this.getTableData();
      },
			//获取用户列表
			getTableData() {
				let para = {
          pageNo: this.pageNo,
          pageSize:this.pageSize,
          keyword: this.filters.keyword,
				};
				this.listLoading = true; //显示加载圈
				this.$http.post("/course/teacher/pagelist",para).then(result=>{
					this.total = result.data.data.total;
					this.tableData = result.data.data.rows;
					this.listLoading = false;  //关闭加载圈
				});
			},
			edit(row){
				// this.$message({ message: "功能未开放", type: 'error' });
        /*for(let p in this.addForm){
          this.addForm[p] = row[p];
        }*/
        this.addForm = Object.assign({}, row);
        this.addFormVisible = true;
			},
			del(){
				this.$message({ message: "功能未开放", type: 'error' });
			},
			batchRemove(){
				this.$message({ message: "功能未开放", type: 'error' });
			},
			addTeacher(){
				// this.$message({ message: "功能未开放", type: 'error' });
        this.addForm = {};
        this.addFormVisible = true;
			},
      addSubmit(){
        //提交
        this.$http.post("/course/teacher/save",this.addForm).then(res=>{
          //{success: true, ..
          var ajaxResult = res.data;
          if(ajaxResult.success){
            this.addFormVisible = false;
            this.$message({
              message: '提交成功',
              type: 'success'
            });
            this.getTableData();
          }else{
            this.$message({
              message: ajaxResult.message,
              type: 'error'
            });
          }
        });
      }

		},
		mounted() {
			this.getTableData();
		}
	}

</script>

<style scoped>

</style>